<?php
namespace app\api\controller;

use app\common\model\Job;
/**
 * ============================================================================
 * DSMall多用户商城
 * ============================================================================
 * 版权所有 2014-2028 长沙德尚网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.csdeshang.com
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * 登出控制器
 */
class Logout extends MobileMember
{
    public function _initialize()
    {
        parent::_initialize(); // TODO: Change the autogenerated stub
    }

    /**
     * @api {POST} api/Logout/index 注销
     * @apiVersion 1.0.0
     * @apiGroup Logout
     * 
     * @apiHeader {String} X-DS-KEY 用户授权token
     * 
     * @apiParam {String} username 用户名
     * @apiParam {String} client 用户端 wap手机端
     * 
     * @apiSuccess {String} code 返回码,10000为成功
     * @apiSuccess {String} message  返回消息
     */
    public function index(){
        if(empty(input('post.username')) || !in_array(input('post.client'), $this->client_type_array)) {
            ds_json_encode(10001,lang('param_error'));
        }

        $mbusertoken_model = model('mbusertoken');

        if ($this->member_info['member_name'] == trim(input('post.username'))) {
            $condition = array();
            $condition['member_id'] = $this->member_info['member_id'];
            $condition['member_clienttype'] = input('post.client');
            $mbusertoken_model->delMbusertoken($condition);
            session(null); //删除session中的member_id下，因为次登录时要整合cookie中的商品到数据库中
            ds_json_encode(10000);
        } else {
            ds_json_encode(10001,lang('param_error'));
        }
    }

    /*
    *注销账户
    */
    public function del_account()
    {   
        $member_model = model('member');
        $member_id = $this->member_info['member_id'];
        $memberInfo = db('member')->where('member_id',$member_id)->find();
        Job::where('uid','=',$member_id)->delete();
        $member_model->save(['member_account_status'  => 0],['member_id' => $member_id]);
        ds_json_encode(10000);
        //$this->index();

    }
}